﻿namespace GameThree;

public partial class MainPage : ContentPage
{
    int count = 0;
    GraphicsDrawable gd;
    Task UpTask;

    public MainPage()
	{
		InitializeComponent();
        gd = new GraphicsDrawable();
        can.Drawable = gd;

        this.Disappearing += MainPage_Disappearing;
        this.Loaded += MainPage_Loaded;
    }
    private void MainPage_Loaded(object sender, EventArgs e)
    {
        UpTask = Task.Factory.StartNew(ShuaXing);
    }

    private void MainPage_Disappearing(object sender, EventArgs e)
    {
        //界面进入后台事件
    }

    /// <summary>
    /// 刷新
    /// </summary>
    private void ShuaXing()
    {
        while (true)
        {
            if (this.Handler != null)
            {
                can.Invalidate();
            }
            Thread.Sleep(500);
        }
    }
    [Obsolete]
    private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
    {
        Label lb = new Label();
        lb.Text = "+1";
        lb.Background = new SolidColorBrush(Colors.Red);
        ui.Add(lb);
        Grid.SetColumn(lb, 1);
        Grid.SetRow(lb, 1);
        lb.Opacity = 1;
        await lb.FadeTo(0, 3000);
        await lb.TranslateTo(0, 100, 3000);

        count++;
        gongde.Text = "功德" + count;
    }
    /// <summary>
    /// 点击木鱼
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void TapGestureRecognizer_Tapped_1(object sender, EventArgs e)
    {
        count++;
        gongde.Text = "功德" + count;
        gd.DrawItems.Add(new DrawItem() { DrwaCount = 0, DrawText = "+1" });
        //can.InvalidateVisual();
    }

}

